package com.zzyl.controller;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.AlertRuleDto;
import com.zzyl.service.AlertRoleService;
import com.zzyl.vo.AlertRuleVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.models.auth.In;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/alert-rule")
@Api(tags="报警规则接口")
public class AlertRoleController extends BaseController{

    @Autowired
    AlertRoleService alertRoleService;

    @PostMapping("/create")
    @ApiOperation("新增报警")
    public ResponseResult addRole(@RequestBody AlertRuleDto alertRuleDto){
        alertRoleService.addRole(alertRuleDto);
        return success();
    }

    @GetMapping("/get-page")
    @ApiOperation("分页查询报警")
    public ResponseResult<PageResponse<AlertRuleVo>> page(Integer pageNum, Integer pageSize, String alertRuleName, String functionName, String productKey){
        PageResponse<AlertRuleVo>page= alertRoleService.page(pageNum,pageSize,alertRuleName,functionName,productKey);
        return success(page);
    }

    @GetMapping("/read/{id}")
    @ApiOperation("获取单个警告规则")
    public ResponseResult<AlertRuleVo> getById(@PathVariable("id")Integer id){
        AlertRuleVo alertRuleVo= alertRoleService.getById(id);
        return success(alertRuleVo);
    }

    @PutMapping("/update/{id}")
    @ApiOperation("修改警告规则")
    public ResponseResult updateById(@RequestBody AlertRuleDto alertRuleDto){
        alertRoleService.updateById(alertRuleDto);
        return success();
    }


    @DeleteMapping("/delete/{id}")
    @ApiOperation("删除报警")
    public ResponseResult deleteById(@PathVariable("id")Integer id){
        alertRoleService.deleteById(id);
        return success();
    }

    @PutMapping("/{id}/status/{status}")
    @ApiOperation("启用禁用")
    public ResponseResult deleteById(@PathVariable("id")Integer id, @PathVariable("status")Integer status){
        alertRoleService.setStatus(id,status);
        return success();
    }


}
